<%@page pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="pmes" uri="http://www.pmes.com/functions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <%@include file="/WEB-INF/jsp/common/common.jsp"%>
	<script>
    $(function(){
    	$("#insertBtn").click(function(){
    		//window.location.href = "${APP_PATH}/bt/add.do";
    		$('#btWindow').window('open');
    	});
    	$("#searchBtn").click(function(){
    		var rows = $('#dataTable').datagrid('getSelections');
    		if ( rows.length == 0 ) {
    			$.messager.alert('系统提示信息', "必须选择需要查看审批历史的故障单信息",'error');
    		} else if ( rows.length > 1 ) {
    			$.messager.alert('系统提示信息', "只能选择一条故障单信息查看审批历史",'error');
    		} else {
        		var row = rows[0];
        		$('#historyWindow').window('open');
        		// 查询历史数据
        		$("#historyTable").datagrid({
        			url : "${APP_PATH}/bt/queryHistory.do",
        			method : "GET",
        			queryParams : {
        				id : row.id
        			}
        		});
    		}
    	});
    	$("#updateBtn").click(function(){
    		var rows = $('#dataTable').datagrid('getSelections');
    		if ( rows.length == 0 ) {
    			$.messager.alert('系统提示信息', "必须选择需要修改的故障单信息",'error');
    		} else if ( rows.length > 1 ) {
    			$.messager.alert('系统提示信息', "只能选择一条故障单信息进行修改",'error');
    		} else {
        		var row = rows[0];
        		//window.location.href = "${APP_PATH}/user/edit.do?id="+row.id;
				$('#btUpdateForm').form('load',row);
        		$('#btUpdateWindow').window('open');
    		}
    	});
    	$("#assignBtn").click(function(){
    		var rows = $('#dataTable').datagrid('getSelections');
    		if ( rows.length == 0 ) {
    			$.messager.alert('系统提示信息', "必须选择需要派障的故障单信息",'error');
    		} else if ( rows.length > 1 ) {
    			$.messager.alert('系统提示信息', "只能选择一条故障单信息进行派障",'error');
    		} else {
        		var row = rows[0];
        		if ( row.status != '0' ) {
        			$.messager.alert('系统提示信息', "只能对新建的故障单信息进行派障",'error');
        		} else {
    				$.ajax({
    					type : "POST",
    					url  : "${APP_PATH}/bt/doAssign.do",
    					data : {
    						"id" : row.id
    					},
    					beforeSend : function() {
    						$.messager.progress();
    						return true;
    					},
    					success : function( r ) {
    						$.messager.progress('close');
    						if ( r.success ) {
    							$.messager.alert('系统提示信息', "故障单信息派障成功",'info', function(){
    								$('#dataTable').datagrid('reload');
    							});
    						} else {
    							$.messager.alert('系统提示信息', "故障单信息派障失败",'error');
    						}
    					}
    				});
        		}

    		}
    	});
    	$("#deleteBtn").click(function(){
    		var rows = $('#dataTable').datagrid('getSelections');
    		if ( rows.length == 0 ) {
    			$.messager.alert('系统提示信息', "必须选择需要删除的故障单信息",'error');
    		} else {
    			$.messager.confirm('系统提示信息', '删除选择的故障单信息，是否继续?', function(r){
    				if (r){
	        			var paramObj = {};
	        			
	        			$.each( rows, function(i, row) {
	        				paramObj["bts["+i+"].id"] = row.id;
	        			} );

	        			$.ajax({
	        				type : "POST",
	        				url  : "${APP_PATH}/bt/deleteBts.do",
	        				data : paramObj,
	        				beforeSend : function() {
	        					return true;
	        				},
	        				success : function( r ) {
	        					if ( r.success ) {
	        						$.messager.alert('系统提示信息', "故障单信息删除成功",'info', function(){
	        							$('#dataTable').datagrid('reload');
	        						});
	        					} else {
	        						$.messager.alert('系统提示信息', "故障单信息删除失败",'info');
	        					}
	        				}
	        			});
    				}
    			});
    		}
    	});
    });
    function submitUpdateForm() {
		$.messager.progress();
		$('#btUpdateForm').form('submit', {
	        onSubmit: function(){
	        	return true;
	        },
	        success : function( data ) {
	        	$.messager.progress('close');	
	        	var r = eval('(' + data + ')');
	        	if ( r.success ) {
					$.messager.alert('系统提示信息', "故障单信息修改成功",'info', function(){
						$('#dataTable').datagrid('reload');
						$('#btUpdateWindow').window('close');
					});
	        	} else {
	        		$.messager.alert('系统提示信息', "故障单信息修改失败",'error');
	        	}
	        }
		});
    }
	function submitForm(){
		$.messager.progress();
		$('#btForm').form('submit', {
	        onSubmit: function(){
	        	return true;
	        },
	        success : function( data ) {
	        	$.messager.progress('close');	
	        	var r = eval('(' + data + ')');
	        	if ( r.success ) {
					$.messager.alert('系统提示信息', "故障单信息保存成功",'info', function(){
						$('#dataTable').datagrid('reload');
						$('#btWindow').window('close');
					});
	        	} else {
	        		$.messager.alert('系统提示信息', "故障单信息保存失败",'error');
	        	}
	        }
		});
	} 
	</script>
</head>
<body class="easyui-layout">
    <div data-options="region:'center',border:false">
	<table id="dataTable"
	       class="easyui-datagrid"
	       title="归档故障单分页查询表格 "
		   data-options="
		        fit:true,
		        border:false,
		   		singleSelect:false,
		   		collapsible:false,
		   		fitColumns:true,
		   		rownumbers:true,
		   		url:'${APP_PATH}/bt/pageQueryFinished.do',
		   		method:'get',
				pagination:true,
				pageSize:10,
				toolbar:'#tb'
		   ">
		<thead>
			<tr>
			    <th data-options="field:'id',checkbox:true"></th>
				<th data-options="field:'levelLabel',width:100">故障级别</th>
				<th data-options="field:'addressLabel',width:100">故障局点</th>
				<th data-options="field:'remark',width:100">故障描述</th>
				<th data-options="field:'happentime',width:100">故障发生时间</th>
				<th data-options="field:'createtime',width:100">建障时间</th>
				<th data-options="field:'username',width:100">建障人</th>
				<th data-options="field:'statusLabel',width:100">状态</th>
			</tr>
		</thead>
	</table>
	</div>
	<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<a href="#" id="searchBtn" class="easyui-linkbutton" iconCls="icon-search" plain="true">审批历史</a>
		</div>
	</div>
	<div id="historyWindow" class="easyui-window" title="审批历史窗口"
	    data-options="
	        modal:true,
	        closed:true,
	        iconCls:'icon-search'"
	    style="width:500px;height:200px;padding:10px;">
		<table id="historyTable"
		       class="easyui-datagrid"
			   data-options="
			        fit:true,
			        border:false,
			   		singleSelect:false,
			   		collapsible:false,
			   		fitColumns:true,
			   		rownumbers:true
			   ">
			<thead>
				<tr>
					<th data-options="field:'opertype',width:100">审批意见</th>
					<th data-options="field:'authtime',width:100">审批时间</th>
					<th data-options="field:'username',width:100">审批人</th>
					<th data-options="field:'remark',width:100">审批备注</th>
				</tr>
			</thead>
		</table>
	</div>
</body>
</html>
